/*
 * @author[hansen]
 * @version[创建日期，2022/6/1 9:53]
 * @function[icon text widget]
 */

import 'package:flutter/material.dart';

/*
 * @author[hansen]
 * @version[创建日期，2022/5/27 18:10]
 * @function[图标-文本]
 */

class IconTextWidget extends StatelessWidget {
  final String? iconName;
  final double? iconWidth;
  final double? iconHeight;
  final double? iconTextSpace;
  final String? text;
  final TextStyle? textStyle;
  final MainAxisAlignment? mainAxisAlignment;
  final CrossAxisAlignment? crossAxisAlignment;
  final MainAxisSize? mainAxisSize;
  final Axis? direction;

  const IconTextWidget({
    Key? key,
    this.iconName,
    this.iconWidth = 33,
    this.iconHeight = 33,
    this.iconTextSpace = 1,
    this.text,
    this.textStyle = const TextStyle(
      color: Color(0xFF909399),
      fontSize: 10,
    ),
    this.mainAxisAlignment = MainAxisAlignment.center,
    this.crossAxisAlignment = CrossAxisAlignment.center,
    this.mainAxisSize = MainAxisSize.min,
    this.direction = Axis.horizontal,
  })  : assert(iconName != null),
        assert(text != null),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Flex(
      direction: direction ?? Axis.horizontal,
      mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.center,
      crossAxisAlignment: crossAxisAlignment ?? CrossAxisAlignment.center,
      mainAxisSize: mainAxisSize ?? MainAxisSize.min,
      children: [
        Image.asset(
          iconName ?? '',
          width: iconWidth,
          height: iconHeight,
        ),
        SizedBox(
          width: direction == Axis.horizontal ? iconTextSpace : 0,
          height: direction == Axis.vertical ? iconTextSpace : 0,
        ),
        Text(
          text ?? '',
          style: textStyle,
        )
      ],
    );
  }
}
